/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: dings
 * Date: 2024-08-02
 * Time: 20:31
 */
public class Test {
}

class Solution {
        public int minOperations(int[] nums, int x) {
            int sumN = 0;
            for (int i = 0; i < nums.length; i++) {
                sumN += nums[i];
            }
            int target = sumN - x;
            int left = 0;
            int right = 0;
            int maxL = -1;//
            int sum = 0;
            if(target < 0) return -1;
            while (right < nums.length) {
                sum += nums[right];

                while (sum > target) {
                    sum -= nums[left];
                    left++;
                }
                if (sum == target) {
                    maxL = Math.max(maxL,right - left + 1);
                }
                right++;
            }
            return maxL == -1 ? -1 : nums.length - maxL;
        }

    public static void main(String[] args) {
        int[] arr = {8828,9581,49,9818,9974,9869,9991,10000,10000,10000,9999,9993,9904,8819,1231,6309};
        Solution solution= new Solution();
        System.out.println(solution.minOperations(arr,134365));

    }
}